package com.itheima.myfile.myfiledemo;

import java.io.File;

//递归删除文件
public class Test {
    public static void main(String[] args) {
        File file = new File("C:\\Users\\Cloudy\\Desktop\\每日作业");
        deleteFile(file);
    }

    private static void deleteFile(File folder) {
        //1. 进入
        File[] files = folder.listFiles();
        //2. 遍历
        if (files != null) {
            for (File file : files) {
                //3. 判断是否是文件
                if (file.isFile()) {
                    file.delete();
                } else {
                    //4. 判断
                    deleteFile(file);
                    file.delete();
                }
            }
        }
        //删除
        folder.delete();
    }
}
